package com.shd.edanpei.ui.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.shd.edanpei.R;
import com.shd.edanpei.base.BaseActivity;
import com.shd.edanpei.common.Constant;
import com.shd.edanpei.presenter.contract.QuitApprovalContract;
import com.shd.edanpei.presenter.QuitApprovalPresenter;
import com.shd.edanpei.ui.adapter.QuitTeamAdapter;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by mc on 2019/1/2.
 * 退团审批
 */

public class QuitApprovalActivity extends BaseActivity<QuitApprovalPresenter>
        implements QuitApprovalContract.QuitApprovalIView {

    @BindView(R.id.headline)
    TextView headLine;
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;

    private QuitTeamAdapter mAdapter;
    private int teamID;

    @Override
    protected int setLayout() {
        return R.layout.activity_quitapproval;
    }

    @Override
    protected QuitApprovalPresenter bindPresenter() {
        return new QuitApprovalPresenter(this);
    }

    @Override
    protected void initView(@Nullable Bundle savedInstanceState) {
        headLine.setText("退团审批");
        Bundle extras = getIntent().getExtras();
        teamID = extras.getInt(Constant.TEAM_ID);

        mAdapter = new QuitTeamAdapter(this);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(mAdapter);
        mPresenter.refresh(teamID);
    }

    @Override
    protected void initListener() {

        mAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
            @Override
            public void onLoadMoreRequested() {
                mPresenter.loadMore(teamID);
            }
        }, recyclerView);

        mAdapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()) {
                    case R.id.tv_agree:
                        mPresenter.argee(mAdapter.getItem(position).getTeamId(),position);
                        break;
                }
            }
        });
    }

    @OnClick(R.id.iv_headline_back)
    void onBack() {
        finish();
    }

    @Override
    public QuitTeamAdapter getAdapter() {
        return mAdapter;
    }
}
